<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ page contentType="text/html; charset=UTF-8" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<jsp:useBean id="user" class="model.User" scope="session" />
<jsp:useBean id="mfromTown" class="model.Mesto" scope="session" />
<jsp:useBean id="mToTown" class="model.Mesto" scope="session" />
<jsp:useBean id="putnaDuz" class="model.PutnaDuz" scope="session" />
<jsp:useBean id="changedID" class="java.lang.String" scope="session" />

<html>
<head>

<title>Izmena linije</title>

<script language="javascript" src="js/prototype-1.6.0.2.js"></script>
<script language="javascript" src="js/prototype-base-extensions.js"></script>
<script language="javascript" src="js/prototype-date-extensions.js"></script>
<script language="javascript" src="js/datepicker.js"></script>
<link rel="stylesheet" href="css/datepicker.css" />

</head>
<body>
<%
	if (user != null && user.isLoggedIn()) {
%>
<h1>Izmena linije</h1>
<form action="/trips" method=post>
<table>
		<tr>
		<td align="right">Start:</td>
		<td><select name="fromTown">
			<c:forEach var="town" items="${sessionScope.allTowns}">
				<c:if test="${empty mfromTown.sifra.id}">
					<option>${town.naziv}</option>
				</c:if>
				<c:if test="${not empty mfromTown.sifra.id}">
					<c:if test="${mfromTown.sifra.id == town.sifra.id}">
						<option selected="selected">${town.naziv}</option>
					</c:if>
					<c:if test="${mfromTown.sifra.id != town.sifra.id}">
						<option>${town.naziv}</option>
					</c:if>
				</c:if>
			</c:forEach>
		</select></td>
	</tr>
	<tr>
		<td align="right">Cilj:</td>
		<td><select name="toTown">
			<c:forEach var="town" items="${sessionScope.allTowns}">
				<c:if test="${empty mToTown.sifra.id}">
					<option>${town.naziv}</option>
				</c:if>
				<c:if test="${not empty mToTown.sifra.id}">
					<c:if test="${mToTown.sifra.id == town.sifra.id}">
						<option selected="selected">${town.naziv}</option>
					</c:if>
					<c:if test="${mToTown.sifra.id != town.sifra.id}">
						<option>${town.naziv}</option>
					</c:if>
				</c:if>
			</c:forEach>
		</select></td>
	</tr>
	<tr>
		<td align=right>Cena:</td>
		<td><input type="text" name="cena" value="${putnaDuz.cena}"
			size="10" maxlength="7"> din.</td>
	</tr>
	<tr>
		<c:set var="polazak">
			<fmt:formatDate pattern="hh:mm" value="${putnaDuz.polazak}" />
		</c:set>

		<td align=right>Polazak:<br>
		<small>(satnica)</small></td>
		<td><input type="text" id="my_datepicker" name="polazak"
			value="${polazak}" size="5" class="timepicker" /></td>
	</tr>
	<tr>
		<c:set var="dolazak">
			<fmt:formatDate pattern="hh:mm" value="${putnaDuz.dolazak}" />
		</c:set>
		<td align=right>Dolazak:<br>
		<small>(satnica)</small></td>
		<td><input type="text" id="my_datepicker2" name="dolazak"
			value="${dolazak}" size="5" class="timepicker" /></td>
	</tr>
	<tr>
	<!-- Radi ko ZMAJ! -->
		<td align="right" vAlign=top>Povlastice:<br />
		<small>(drzite CTRL za vise)</small></td>
		<td><select name="bens" multiple="multiple" size="5">

			<c:forEach var="readedBen" items="${sessionScope.allBens}">
				<c:set var="rBenID">${readedBen.sifra.id}</c:set>

				<c:set var="contains">false</c:set>
				<c:forEach var="ben" items="${putnaDuz.povlastica}">
					<c:set var="benID">${ben.sifra.id}</c:set>
					<c:if test="${benID eq rBenID}">
						<c:set var="contains">true</c:set>
					</c:if>
				</c:forEach>

				<c:if test="${contains == 'false'}">
					<option value="${readedBen.sifra.id}">${readedBen.naziv}</option>
				</c:if>

				<c:if test="${contains == 'true'}">
					<option selected="selected" value="${readedBen.sifra.id}">${readedBen.naziv}</option>
				</c:if>

			</c:forEach>
		</select></td>
	</tr>

	<tr>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td><input type="hidden" name="ID" value="${changedID}">
		<input type="hidden" name="changed" value="true"></td>
		<td><input type="submit" value="Potvrdi izmene" /></td>
	</tr>
</table>
</form>

<script language="javascript">
	new Control.DatePicker('my_datepicker', {
		icon : 'images/clock.png',
		timePicker : true,
		datePicker : false,
		use24hrs : true,
		timePickerAdjacent : true
	});
</script>
<script>
	new Control.DatePicker('my_datepicker2', {
		icon : 'images/clock.png',
		timePicker : true,
		datePicker : false,
		use24hrs : true,
		timePickerAdjacent : true
	});
</script>
<%
	} else {
%>

<p>Niste se prijavili! <br>
<a href="/logIn">Logovanje</a></p>

<%
	}
%>

<p><a href="/timeTableServlet">Red voznje</a> <br>
<a href="/logIn?logOff=true">Odjava</a></p>

</body>
</html>